package day01;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author feng
 * @Date 2021/12/26 14:27
 * 文件拷贝
 */
public class FileCopy {
    public static void main(String[] args) {
        FileInputStream inputStream = null;
        FileOutputStream outputStream = null;
        String inputPath = "D:\\IO\\1.png";
        byte[] bytes = new byte[8];
        int read = 0;
        try {
            inputStream = new FileInputStream(inputPath);
            outputStream = new FileOutputStream("D:\\IO\\A\\B\\1.png");
            while ((read = inputStream.read(bytes)) != -1) {
                //边读边写
                outputStream.write(bytes, 0, read);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (inputStream == null) {
                    inputStream.close();
                }
                if (inputStream == null) {
                    inputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
